# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=soju
pkgver=0.8.2
pkgrel=0
pkgdesc="User-friendly IRC bouncer"
url="https://soju.im/"
license="AGPL-3.0"
arch="all"
pkgusers="$pkgname"
pkggroups="$pkgname"
install="$pkgname.pre-install"
depends="ca-certificates"
makedepends="go scdoc sqlite-dev"
subpackages="$pkgname-openrc $pkgname-doc $pkgname-utils"
source="$pkgname-$pkgver.tar.gz::https://codeberg.org/emersion/soju/releases/download/v$pkgver/soju-$pkgver.tar.gz
	$pkgname.initd
	config.patch
	makefile.patch
	"

_utils="migrate-db migrate-logs znc-import"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	make GOFLAGS="$GOFLAGS"

	for util in $_utils; do
		cd "$builddir"/contrib/$util
		go build -o "$builddir"/
	done
}

check() {
	go test ./...
}

package() {
	make DESTDIR="$pkgdir" PREFIX=/usr install

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname

	# add additional docs
	install -Dm644 -t "$pkgdir"/usr/share/doc/$pkgname doc/*.md

	for util in $_utils; do
		install -Dm755 $util "$pkgdir"/usr/bin/soju-$util
	done
}

utils() {
	pkgdesc="Utilities for soju"

	for util in $_utils; do
		amove usr/bin/soju-$util
	done
}

sha512sums="
e373a15ef6c4f001cfae87e4e7b7af84a7df7e674cab6c53e72a6baa94cafcca5beacae86a966107634642531780f8f1e1a2ad7d939572edd61d979bcb30165a  soju-0.8.2.tar.gz
1f09a8d7eea73d5d81cdcad8a3a78fe30fc19742c13042ad2ee0448edf4108b2daf7da6fbbd4141b23fe1abd9cb931303efa6440d281a954e5d6d4956a291f7e  soju.initd
2f09bdb2efd0cd2f5f138dac7d5a4d02cfee6c46fc103c30fa70a238f322617b53ffd4b6ce6d0a8410375dd7229a68dcd6318e2b9651c5b559fff70fbca7adb3  config.patch
b647576f50ab03a90d9ab9062d97ecf050fd6e7eeba77200e05e4577733886a4ca85c7cef68d476fc611bfca41f01eecca7d3f8ce8d03431872ccb78ea2f64db  makefile.patch
"
